#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "choselevelwindow.h"
#include <QMouseEvent>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    ChoseLevelWindow* choseLevel = new ChoseLevelWindow;
    connect(choseLevel,&ChoseLevelWindow::backMainWIndow,[=](){
        choseLevel->hide();
        this->setGeometry(choseLevel->geometry());
        this->show();
    });

    //窗口设置
    this->setFixedSize(350,600);
    this->setWindowIcon(QIcon(":/coin/res/Coin0001.png"));
    this->setWindowTitle("翻金币");

    myPushButton* startBtn = new myPushButton(":/button/res/MenuSceneStartButton.png");
    startBtn->setParent(this);
    startBtn->move(0.5*(this->width()-startBtn->width()),this->height()*0.7);

    connect(startBtn,&QPushButton::pressed,[=](){
        startBtn->jumpup();
    });
    connect(startBtn,&QPushButton::released,[=](){
        startBtn->jumpdown();
        QTimer::singleShot(410,[=](){
            this->hide();
            choseLevel->setGeometry(this->geometry());
            choseLevel->show();
        });
    });
}

void MainWindow::paintEvent(QPaintEvent *)
{
    QPainter painter(this);
    QPixmap pix;

    pix.load(":/background/res/PlayLevelSceneBg.png");
    painter.drawPixmap(0,0,this->width(),this->height(),pix);

    pix.load(":/background/res/Title.png");
    pix=pix.scaled(pix.width()*0.5,pix.height()*0.5);
    painter.drawPixmap(10,30,pix);
}

MainWindow::~MainWindow()
{
    delete ui;
}

